﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MixScriptWeb.control;
using MixScriptWeb.Share;
using MixScript.BLL;
using MixScriptWeb.AppCode.gjips;
using MixScript.BLL.MM;
using MixScript.Appl.Lib;


namespace MixScriptWeb.Jideco.MM
{
    public partial class frmPayAging : cCommonWeb//, IMIxCommon
    {
        private static cSearchHelp osch;
        private static DataTable dt;
        private static DateTime tglPO;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                tglPO = DateTime.Now;                
                txtDate1.CssClass += " ritonli";
                txtDate1.Text = tglPO.ToString("dd-MM-yyyy");                
                osch = new cSearchHelp("SRCSUPGJ");
                LoadData(); }
        }
        public bool isvalid()
        {
            return true;
        }
        void bindtogv(DataTable dt)
        {
            try
            {
                gvList.DataSource = dt;
                gvList.DataBind();
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }
        private void LoadData()
        {
            try
            {

                dt = new DataTable();
                if (osch.FillGrid(ref dt, osch.sTableName, osch.arrField))
                {
                    bindtogv(dt);
                }

            }
              catch (Exception ex)
            {

                throw ex;
            }
        }

        
        protected void chkAllHeader_CheckedChanged(object sender, EventArgs e)
        {
            CheckBox chkAll = new CheckBox();
            CheckBox chk;
            chkAll = (CheckBox)gvList.HeaderRow.Cells[0].FindControl("chkAllHeader");
            for (int i = 0; i < gvList.Rows.Count; i++)
            {
                chk = new CheckBox();
                chk = (CheckBox)gvList.Rows[i].Cells[0].FindControl("chkAll");
                chk.Checked = chkAll.Checked;

            }

        }

        protected void btnSubmit_Click(Object sender, EventArgs e)
        {
            try
            {

                String param = "";
                Session["paramxx"] = "";                
                for (int i = 0; i < gvList.Rows.Count; i++)
                {
                    CheckBox chk = new CheckBox();
                    chk = (CheckBox)gvList.Rows[i].Cells[0].FindControl("chkAll");
                    if (chk.Checked)
                    {
                        if (param == "")
                            param = gvList.Rows[i].Cells[1].Text.TrimEnd();
                        else
                            param = param + "," + gvList.Rows[i].Cells[1].Text.TrimEnd();
                    }
                }
                Session["paramxx"] = param;
                Session["tglxx"] = txtDate1.Text.Substring(6, 4) + "-" + txtDate1.Text.Substring(3, 2) + "-" + txtDate1.Text.Substring(0, 2);
                string sscript = "";
                sscript += "<script>";

                sscript += "window.open('../print/rptid-21,GRNID-" + "" + ",suppid-" + "" + ",dl.html', '_blank');";
                sscript += "</script>";
                ClientScript.RegisterStartupScript(GetType(), "report", sscript);     
                

            }
            catch (Exception ex)
            {
                System.IO.File.AppendAllText(Request.MapPath(Request.ApplicationPath) + "Error.log", ex.Message + Environment.NewLine);
            }

        }

    }
}